
BIN := symdb
C_SRC :=  
CXX_SRC :=          \
./sym-name-table.cc             \
./database.cc                   \
./sym-info-table.cc             \
./c-sym-name-table.cc           \
./cpp-sym-name-table.cc         \
./symdb-conf.cc                 \
./symdb-main.cc                 \
./io-util.cc                    \
./filepath-util.cc              \
./string-util.cc                \
./sym-find-print.cc             \
./sym-main.cc                   \
./main.cc                       \
./sym-add-main.cc               \
./sym-find-main.cc              \
./sym-modify-main.cc


CFLAGS :=  -O2
CXXFLAGS :=  -std=c++11 -Wall -O2
LDFLAGS :=  -lsqlite3
# 安装路径的前缀.
PREFIX := /usr

####### 以下不需要配置 ###############
OBJ_DIR := objs
DEP_DIR := $(OBJ_DIR)/deps
BIN_DIR := bin

C_OBJS := $(C_SRC:.c=.c.o)
CXX_OBJS := $(CXX_SRC:.cc=.cc.o)
ALL_DEPS := $(C_OBJS:.o=.dep)
ALL_DEPS += $(CXX_OBJS:.o=.dep)

C_OBJS := $(foreach var,$(C_OBJS),$(OBJ_DIR)/$(var))
CXX_OBJS := $(foreach var,$(CXX_OBJS),$(OBJ_DIR)/$(var))
ALL_DEPS := $(foreach var,$(ALL_DEPS),$(DEP_DIR)/$(var))

all: $(BIN_DIR)/$(BIN)
	

include $(ALL_DEPS)

$(DEP_DIR)/%.dep: % 
	@if [ ! -d $(dir $@) ] ; then mkdir -pv $(dir $@); fi
	gcc -E -M -MQ $(OBJ_DIR)/$*.o -MQ $@ -MF $@ $<
	
$(OBJ_DIR)/%.c.o: %.c 
	@if [ ! -d $(dir $@) ] ; then mkdir -pv $(dir $@); fi
	gcc -c $< -o $@ $(CFLAGS)

$(OBJ_DIR)/%.cc.o: %.cc 
	@if [ ! -d $(dir $@) ] ; then mkdir -pv $(dir $@); fi
	g++ -c $< -o $@ $(CXXFLAGS)

$(BIN_DIR)/$(BIN): $(C_OBJS) $(CXX_OBJS) 
	@if [ ! -d $(BIN_DIR) ] ; then mkdir -pv $(BIN_DIR); fi
ifeq ($(strip $(CXX_SRC)),)
	gcc -o $(BIN_DIR)/$(BIN) $(C_OBJS) $(CXX_OBJS) $(LDFLAGS)
else
	g++ -o $(BIN_DIR)/$(BIN) $(C_OBJS) $(CXX_OBJS) $(LDFLAGS)
endif

clean:
	-@rm -v  $(ALL_DEPS) $(C_OBJS) $(CXX_OBJS) $(BIN_DIR)/$(BIN)

install:
	@mkdir -pv $(PREFIX)/bin
	@cp $(BIN_DIR)/$(BIN) $(PREFIX)/bin -v
	@ln -svf $(PREFIX)/bin/$(BIN)  $(PREFIX)/bin/sym	

.PHONY: all clean mkObjDir mkDepDir mkBinDir install
 
 
